{extend name="layout" /}
{block name="content"}
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">{$pathCurrent['name']}</li>
        <li><a href="{:url('option')}">添加</a></li>
    </ul>
</div>

<div class="layui-card-body">
    <div data-model="table-bind">
        <table class="layui-hide" id="data_table" lay-filter="data_table" data-table></table>
    </div>
</div>
<script type="text/html" id="barTar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" data-del data-id="{{d.id}}" data-table="user">删除</a>
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">批量显示</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">批量禁止</button>
    </div>
</script>
<script type="text/html" id="sysTar">
    {{#  if(d.status == 1){ }}
    <button type="button" class="layui-btn layui-btn-normal">正常</button>
    {{#  } else { }}
    <button type="button" class="layui-btn layui-btn-danger">关闭</button>
    {{#  } }}
</script>
{/block}
{block name="js"}
<script type="text/javascript">
    var mixin = {};
    var SlefUrl = this.location.href;
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#data_table',
            url:SlefUrl,
            limit:20,
            cellMinWidth: 80,
            toolbar: '#toolbarDemo',
            cols: [[
                {type:'checkbox',fixed: 'left'},
                {field:'id',width:80, title: 'ID', sort: true,align:'center'}
                ,{field:'money', sort: true, width:80, title: '金额'}
                ,{field:'status_name', title: '状态'}
                ,{field:'created_at', title: '创建时间',width:150}
                ,{field:'op', title: '操作',toolbar: '#barTar', width:150,align:'center'}
            ]],
            page: true
        });
        table.on('tool(data_table)', function(obj){
            var data = obj.data;
            data.table = "recharge_money";
            if(obj.event === 'del'){
                layer.confirm('确定删除吗？', function(index){
                    layer.close(index);
                    form.formDel(data,obj);
                });
            }
        });

        //头工具栏事件
        table.on('toolbar(data_table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    //批量修改，
                    var data = checkStatus.data;
                    if(data.length == 0){
                        layer.alert('至少选择一条数据');
                        return;
                    }
//                table.render({
//                    elem: '#demp'
//                    ,url: 'update_status'
//                    ,parseData: function(res){ //res 即为原始返回的数据
//                        console.log(res);
//                    }
//                    //,…… //其他参数
//                });
                    $.ajax({
                        type: "POST",
                        url: "update_status",
                        data: {data:JSON.stringify(data),table:'recharge_money',filed:'status',filed_value:1},
                        dataType: "json",
                        success: function(data){
                            layer.msg(data.msg);
                            if(data.code == 1){
                                window.location.href = SlefUrl;
                            }
                        }
                    });
                    return;
                    //layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    if(data.length == 0){
                        layer.alert('至少选择一条数据');
                        return;
                    }
                    $.ajax({
                        type: "POST",
                        url: "update_status",
                        data: {data:JSON.stringify(data),table:'recharge_money',filed:'status',filed_value:2},
                        dataType: "json",
                        success: function(data){
                            layer.msg(data.msg);
                            if(data.code == 1){
                                window.location.href = SlefUrl;
                            }
                        }
                    });
                    return;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });
    });
</script>
{/block}